$(function() {
	//内容区加载
	mui.ready(function() {

	});
	var record = 0; //每次返回的数据的长度
	// var size = 2;
	//请求JSON
	var userid = localStorage.getItem('userid');
	var token = localStorage.getItem('token');

	var url = domain + "/dtwbgl/wbmsg.h5";


	var kinds = {
		"1": {
			"name": "维保",
			"class": ""
		},
		"3": {
			"name": "紧急",
			"class": "wei",
		}
	};
	var now = getNowFormatDate();
	// var size = Dpage // 每页
	// Request(url, req);
	layui.use('flow', function() {
		var $ = layui.jquery; //不用额外加载jQuery，flow模块本身是有依赖jQuery的，直接用即可。
		var flow = layui.flow;
		flow.load({
			elem: '.warn-list' //指定列表容器
				,
			done: function(page, next) { //到达临界点（默认滚动触发），触发下一页
				var req = {
					currtime: now,
					page: page,
					pagenum: Dpage,
					userid: userid,
					token: token,
				}
				$.ajax(url, {
					// data: JSON.stringify(req),
					data: req,
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 30000, //超时时间
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
					},
					async: true, //true异步加载
					success: function(data) {
						if (data.code == 2001) {
							var oldList = data.data.old;
							var newList = data.data.new;
							var pages = (oldList.total / req.pagenum);

							var html = '';
							if (newList.count > 0 && page <= 1) { // 新数据
								html = generateHtml(newList.msg);
							} else { // 旧数据
								html = generateHtml(oldList.rows);
							}
							next(html, page < pages);
						} else if (data.code == 2002) {
							mui.alert(data.msg);
							mui.openWindow({
								url: 'login.html',
								id: 'login.html'
							})
						} else {
							mui.alert(data.msg);
							mui.openWindow({
								url: '404.html',
								id: '404.html'
							})
						}

					},
					error: function(xhr, type, errorThrown) { //异常处理； console.log(type);
						mui.alert(type);
						mui.openWindow({
							url: '../../login.html',
							id: 'login.html'
						})
					}
				});
			}
		});
	});

	function generateHtml(list) {
		var html = '';
		list.forEach(function(e, i) {
			var item = e.messdata;
			if ('dtlist' in item) {
				return false;
			}
			var kindsName = kinds[item.kind].name;
			var kindsClass = kinds[item.kind].class;

			html +=
				`<li class="${kindsClass}">
						<a href="javascript:;">
							<!--通知-->
						<div class="warn-bianma">
						<h2>确认通知</h2>
						<div class="warn-bianma-state">
						<p class="active">
						<span>${kindsName}</span>
						</p>
						</div>
						</div>
							<!--横线半圆样式-->
						<div class="warn-hx">
						<i></i><i></i>
						</div>
							<!--工单-->
						<div class="warn-zhucema">
						<h3>工单号 ：${item.order}</h2>
				</div>
					<!--时间-->
				<div class="warn-zhucema">
						<h3>确认时间：${item.timestamp}</h2>
				</div>
				</a>
				</li>	`;
		});

		return html;
	}



	function Request(url, req) {

	};
})
